Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Commit f7b43a5bd7f043415dcd9592386e51c518a1df3a


Parents : 985372c
Author : Ivan <ivan@quad4.io>
Signature : Signature validation error
Date : 2026-05-02T16:40:06-05:00

test(tests): enable translator_libretranslate in language support tests and improve mock hash handling in MicronWasmLoader tests

Changes

2 files changed, 24 insertions(+), 12 deletions(-)


Diff

diff --git a/tests/backend/test_translator_handler_extended.py b/tests/backend/test_translator_handler_extended.py
index 1e1d15ac..0a33a319 100644
--- a/tests/backend/test_translator_handler_extended.py
+++ b/tests/backend/test_translator_handler_extended.py
@@ -58,6 +58,7 @@ def test_get_supported_languages_libretranslate(mock_session_cls):
handler.has_argos_lib = False
handler.has_argos_cli = False
handler.has_requests = True
+ handler.translator_libretranslate_enabled = True
langs = handler.get_supported_languages()
assert len(langs) == 2
assert langs[0]["code"] == "en"
@@ -183,6 +184,7 @@ def test_libretranslate_get_languages_disallows_redirects(mock_session_cls):
handler.has_argos_lib = False
handler.has_argos_cli = False
handler.has_requests = True
+ handler.translator_libretranslate_enabled = True
handler.get_supported_languages()
assert mock_session.get.call_args.kwargs.get("allow_redirects") is False

diff --git a/tests/frontend/MicronWasmLoader.test.js b/tests/frontend/MicronWasmLoader.test.js
index 17d44901..497d523d 100644
--- a/tests/frontend/MicronWasmLoader.test.js
+++ b/tests/frontend/MicronWasmLoader.test.js
@@ -101,18 +101,23 @@ describe("MicronWasmLoader.js", () => {
});
// Mock crypto.subtle.digest to return hash matching embedded SRI for test data
- const mockWasmHash = __MICRON_WASM_SRI_WASM__?.replace("sha384-", "") || "";
- const mockExecHash = __MICRON_WASM_SRI_EXEC__?.replace("sha384-", "") || "";
+ // Use embedded hashes if available, otherwise generate deterministic mock hashes
+ const embeddedWasmHash = __MICRON_WASM_SRI_WASM__?.replace("sha384-", "");
+ const embeddedExecHash = __MICRON_WASM_SRI_EXEC__?.replace("sha384-", "");
+
+ // Create deterministic 48-byte mock hashes (SHA-384 output size) if embedded not available
+ const mockWasmHash =
+ embeddedWasmHash || "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
+ const mockExecHash =
+ embeddedExecHash || "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB";
+
vi.stubGlobal("crypto", {
subtle: {
digest: vi.fn(async (algo, buf) => {
// Return different hash based on buffer size to distinguish wasm_exec.js vs wasm
- const hash =
- buf.byteLength < 1000
- ? mockExecHash // wasm_exec.js is smaller
- : mockWasmHash; // wasm is larger
- // Convert base64 to ArrayBuffer
- const binary = atob(hash);
+ const hashB64 = buf.byteLength < 1000 ? mockExecHash : mockWasmHash;
+ // Convert base64 to ArrayBuffer (48 bytes for SHA-384)
+ const binary = atob(hashB64);
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) {
bytes[i] = binary.charCodeAt(i);
@@ -164,13 +169,18 @@ describe("MicronWasmLoader.js", () => {
});
// Mock crypto.subtle.digest to return hash matching embedded SRI for test data
- const mockWasmHash = __MICRON_WASM_SRI_WASM__?.replace("sha384-", "") || "";
- const mockExecHash = __MICRON_WASM_SRI_EXEC__?.replace("sha384-", "") || "";
+ const embeddedWasmHash = __MICRON_WASM_SRI_WASM__?.replace("sha384-", "");
+ const embeddedExecHash = __MICRON_WASM_SRI_EXEC__?.replace("sha384-", "");
+ const mockWasmHash =
+ embeddedWasmHash || "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
+ const mockExecHash =
+ embeddedExecHash || "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB";
+
vi.stubGlobal("crypto", {
subtle: {
digest: vi.fn(async (algo, buf) => {
- const hash = buf.byteLength < 1000 ? mockExecHash : mockWasmHash;
- const binary = atob(hash);
+ const hashB64 = buf.byteLength < 1000 ? mockExecHash : mockWasmHash;
+ const binary = atob(hashB64);
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) {
bytes[i] = binary.charCodeAt(i);


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────